package com.yanqu.road.server.cmd.wingroom.message;

import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.wingroom.WingRoomMessageMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author ：zfr
 * @date ：2022/3/20 2:03
 */
@Cmd(code = GameProtocol.S_WING_ROOM_CROSS_GIVE_LIKE, desc = "跨服来点赞")
public class CrossGiveLikeCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        WingRoomProto.GiveLikeCrossReqMsg crossReqMsg = WingRoomProto.GiveLikeCrossReqMsg.parseFrom(packet.getBytes());
        WingRoomProto.GiveMessageLikeRespMsg.Builder respMsg = WingRoomMessageMgr.giveMessageLike(packet.getPlayerId(), crossReqMsg.getGuestUserId());
        WingRoomProto.GiveLikeRespCrossMsg.Builder respCrossMsg = WingRoomProto.GiveLikeRespCrossMsg.newBuilder();
        respCrossMsg.setRespMsg(respMsg);
        respCrossMsg.setGuestServerId(crossReqMsg.getGuestServerId());
        respCrossMsg.setGuestUserId(crossReqMsg.getGuestUserId());
        respCrossMsg.setOwnerServerId(GameServer.getInstance().getServerId());
        respCrossMsg.setOwnerUserId(packet.getPlayerId());
        YanQuMessage message = YanQuMessageUtils.buildMessage(CrossProtocol.C_WING_ROOM_GIVE_LIKE_RESP, respCrossMsg);
        GamePlayerMgr.sendPacket(0, message);
    }
}
